Self join correlates rows of a table with the other rows of the same table. It is used when a table has to be joined to itself to produce results.
Example
First you have to create a table EmpTable and enter the details like this:
EmpIDEmpNameEmpMgrID
1Smith2
2Sai3
3Suresh1
4Bill2
5Steve4
SELECT E2.EMPNAME,E1.EMPNAME as 'MANAGER' FROM EmpTable E1 INNER JOIN EmpTable E2 ON E1.EMPID=E2.EMPMGRID
Output
EmpNameManager
SureshSmith
SmithSai
BillSai
SaiSuresh
SteveBill
Liked By
Write Answer
How to use self join in sql server and what's it's important.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
AVADHESH PATEL
16-May-2013Self Join
Self join correlates rows of a table with the other rows of the same table. It is used when a table has to be joined to itself to produce results.
Example
First you have to create a table EmpTable and enter the details like this:
EmpID EmpName EmpMgrID
1 Smith 2
2 Sai 3
3 Suresh 1
4 Bill 2
5 Steve 4
Output